package com.rainbow.support.lock.zookeeper.properties;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author 傅为地
 * Zookeeper分布式锁配置项
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix=ZookeeperLockProperties.EXTRA_ZOOKEEPER_LOCK_PREFIX)
public class ZookeeperLockProperties {

	/**
	 * 配置项前缀
	 */
	public static final String EXTRA_ZOOKEEPER_LOCK_PREFIX = "extra.zookeeper";

	/**
	 * zookeeper锁
	 */
	private Zookeeper lock = new Zookeeper();

	/**
	 * zookeeper锁配置类
	 */
	@Data
	public static class Zookeeper {
		/**
		 * 是否开启zookeeper锁
		 */
		private boolean enable = true;
		/**
		 * 连接Zookeeper服务器的列表. 包括IP地址和端口号. 多个地址用逗号分隔. 如: host1:2181,host2:2181
		 */
		private String serverLists = "127.0.0.1:2181";

		/**
		 * 命名空间.
		 */
		private String namespace = "zookeeper_distributed_lock";

		/**
		 * 等待重试的间隔时间的初始值. 单位毫秒.
		 */
		private int baseSleepTimeMilliseconds = 1000;

		/**
		 * 等待重试的间隔时间的最大值. 单位毫秒.
		 */
		private int maxSleepTimeMilliseconds = 3000;

		/**
		 * 最大重试次数.
		 */
		private int maxRetries = 3;

		/**
		 * 会话超时时间. 单位毫秒.
		 */
		private int sessionTimeoutMilliseconds;

		/**
		 * 连接超时时间. 单位毫秒.
		 */
		private int connectionTimeoutMilliseconds;

		/**
		 * 最大持有锁时间.默认30秒
		 */
		private long holdTime = 30;

		/**
		 * 连接Zookeeper的权限令牌. 缺省为不需要权限验证.
		 */
		private String digest;
	}

}
